using System;
namespace Example46
{
///
/// Summary description for Class1.
///
class Replace
{
String myString;
public Replace(String s)
{
myString = s;
}
public String MyReplace(String oldWord, String newWord)
{
String temp = myString;
int position = temp.IndexOf(oldWord);
while (position != -1)
{
temp = temp.Substring(0,position) + newWord +
temp.Substring(position + oldWord.Length);
position = temp.IndexOf(oldWord, position + newWord.Length);
}
return temp;
}
public override string ToString()
{
return myString;
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Enter a String which includes \"fish\": ");
Replace phrase = new Replace(Console.ReadLine());
Console.WriteLine("pharse= " + phrase);
String changed = phrase.MyReplace("fish","table");
Console.WriteLine("The new string is {0}", changed);
}
}
}